package com.bangyu.monitor.core.handler;

import com.bangyu.monitor.core.util.InfluDbRepositoryUtil;
import com.bangyu.monitor.modular.system.entity.DeviceIndicator;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Auther: zhangxue
 * @Date: 19/11/13 22:33
 * @Description:
 */
@Slf4j
public class IndicatorHandler implements Runnable{

    private static ExecutorService executor = Executors.newFixedThreadPool(2);

    private List<DeviceIndicator> indicators;

    public IndicatorHandler(List<DeviceIndicator> indicators) {
        this.indicators = indicators;
    }

    @Override public void run() {
        try {
            if(CollectionUtils.isNotEmpty(indicators)){
                InfluDbRepositoryUtil repositoryUtil = new InfluDbRepositoryUtil();
                repositoryUtil.batchInsertIndicator(indicators);
            }
        }catch (Exception e){
            log.error("插入指标数据失败",e);
        }
    }

    public void execute(){
        executor.execute(this);
    }
}
